package top.kpromise.user.service_imp;

import org.springframework.stereotype.Service;
import top.kpromise.user.mapper.UserTokenMapper;
import top.kpromise.user.model.response.UserTokenModel;
import top.kpromise.user.service.UserTokenService;
import top.kpromise.user.utils.DateUtils;

import java.util.Date;

@Service
public class UserTokenServiceImp implements UserTokenService {

    private final UserTokenMapper userTokenMapper;

    public UserTokenServiceImp(UserTokenMapper userTokenMapper) {
        this.userTokenMapper = userTokenMapper;
    }

    @Override
    public UserTokenModel getToken(String userId, String clientId) {
        return userTokenMapper.getToken(userId, clientId);
    }

    @Override
    public void updateToken(UserTokenModel userTokenModel) {
        userTokenModel.setUpdateAt(DateUtils.currentDate());
        userTokenMapper.updateToken(userTokenModel);
    }

    @Override
    public void insertToken(UserTokenModel userTokenModel) {
        Date now = DateUtils.currentDate();
        userTokenModel.setCreateAt(now);
        userTokenModel.setUpdateAt(now);
        userTokenMapper.insertToken(userTokenModel);
    }
}
